package refactortips.editors.codeSmells;

import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.ui.forms.widgets.Form;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.wb.swt.ResourceManager;
import org.eclipse.wb.swt.SWTResourceManager;

import refactortips.editors.AbstractRefactorTipsEditor;
import refactortips.editors.CommandMouseAdapter;

public class DuplicateCodeEditor extends AbstractRefactorTipsEditor {

	private final FormToolkit formToolkit = new FormToolkit(Display.getDefault());

	public DuplicateCodeEditor() {
	}

	/**
	 * Create contents of the editor part.
	 * @param parent
	 */
	@Override
	public void createPartControl(Composite parent) {
		
		Form frmCodeSmell = formToolkit.createForm(parent);
		formToolkit.paintBordersFor(frmCodeSmell);
		frmCodeSmell.setText("Duplicate Code");
		frmCodeSmell.getBody().setLayout(new FillLayout(SWT.HORIZONTAL));
		
		TabFolder tabFolder = new TabFolder(frmCodeSmell.getBody(), SWT.NONE);
		formToolkit.adapt(tabFolder);
		formToolkit.paintBordersFor(tabFolder);
		
		ScrolledComposite sc = new ScrolledComposite(tabFolder, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
		sc.setExpandHorizontal(true);
	    sc.setExpandVertical(true);
		
		TabItem tbtmDescription = new TabItem(tabFolder, SWT.NONE);
		tbtmDescription.setText("Descri\u00E7\u00E3o");
		
		ScrolledComposite scrolledComposite = new ScrolledComposite(tabFolder, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
		tbtmDescription.setControl(scrolledComposite);
		formToolkit.paintBordersFor(scrolledComposite);
		scrolledComposite.setExpandHorizontal(true);
		scrolledComposite.setExpandVertical(true);
		
		Composite composite_3 = new Composite(scrolledComposite, SWT.NONE);
		formToolkit.adapt(composite_3);
		formToolkit.paintBordersFor(composite_3);
		composite_3.setLayout(null);
		
		Label lblDescription = new Label(composite_3, SWT.NONE);
		lblDescription.setBounds(10, 10, 102, 25);
		lblDescription.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		lblDescription.setFont(SWTResourceManager.getFont("Segoe UI", 14, SWT.BOLD));
		formToolkit.adapt(lblDescription, true, true);
		lblDescription.setText("Descri\u00E7\u00E3o");
		
		Label lblImageDontRepeat = new Label(composite_3, SWT.NONE);
		lblImageDontRepeat.setImage(ResourceManager.getPluginImage("RefactorTips", "images/codeSmells/dontRepeatYourself.png"));
		lblImageDontRepeat.setBounds(81, 62, 350, 350);
		formToolkit.adapt(lblImageDontRepeat, true, true);
		
		Link linkExtractMethod1 = new Link(composite_3, SWT.NONE);
		linkExtractMethod1.setBounds(694, 117, 104, 21);
		linkExtractMethod1.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		linkExtractMethod1.addMouseListener(new CommandMouseAdapter(getSite(), "RefactorTips.commands.extractMethodCommand"));
		formToolkit.adapt(linkExtractMethod1, true, true);
		linkExtractMethod1.setText("<a>Extract Method</a>");
		
		Link linkExtractMethod2 = new Link(composite_3, 0);
		linkExtractMethod2.setText("<a>Extract Method</a>");
		linkExtractMethod2.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		linkExtractMethod2.addMouseListener(new CommandMouseAdapter(getSite(), "RefactorTips.commands.extractMethodCommand"));
		linkExtractMethod2.setBounds(683, 227, 104, 21);
		formToolkit.adapt(linkExtractMethod2, true, true);
		
		Link linkPullUpField = new Link(composite_3, 0);
		linkPullUpField.setText("<a>Pull Up Field</a>");
		linkPullUpField.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		linkPullUpField.setBounds(659, 249, 87, 21);
		formToolkit.adapt(linkPullUpField, true, true);
		
		Link linkExtractMethod3 = new Link(composite_3, 0);
		linkExtractMethod3.setText("<a>Extract Method</a>");
		linkExtractMethod3.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		linkExtractMethod3.addMouseListener(new CommandMouseAdapter(getSite(), "RefactorTips.commands.extractMethodCommand"));
		linkExtractMethod3.setBounds(508, 291, 104, 21);
		formToolkit.adapt(linkExtractMethod3, true, true);
		
		Link linkFormTemplateMethod = new Link(composite_3, 0);
		linkFormTemplateMethod.setText("<a>Form Template Method</a>");
		linkFormTemplateMethod.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		linkFormTemplateMethod.setBounds(498, 332, 163, 21);
		formToolkit.adapt(linkFormTemplateMethod, true, true);
		
		Link linkSubstituteAlgorithm = new Link(composite_3, 0);
		linkSubstituteAlgorithm.setText("<a>Substitute Algorithm</a>");
		linkSubstituteAlgorithm.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		linkSubstituteAlgorithm.setBounds(463, 394, 144, 21);
		formToolkit.adapt(linkSubstituteAlgorithm, true, true);
		
		Link linkExtractClass = new Link(composite_3, 0);
		linkExtractClass.setText("<a>Extract Class</a>");
		linkExtractClass.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		linkExtractClass.addMouseListener(new CommandMouseAdapter(getSite(), "RefactorTips.commands.extractClassCommand"));
		linkExtractClass.setBounds(117, 462, 86, 21);
		formToolkit.adapt(linkExtractClass, true, true);
		
		StyledText styledText = new StyledText(composite_3, SWT.READ_ONLY | SWT.WRAP);
		styledText.setEnabled(false);
		styledText.setDoubleClickEnabled(false);
		styledText.setJustify(true);
		styledText.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		styledText.setText("\t\tDuplica\u00E7\u00E3o de c\u00F3digo \u00E9 comum quando voc\u00EA tem a mesma express\u00E3o em dois ou mais m\u00E9todos da mesma classe. Neste caso voc\u00EA precisa apenas\t\t\t\t\t\t\t\te invocar o c\u00F3digo nos lugares onde o c\u00F3digo duplicado estava sendo chamado.");
		styledText.setBounds(463, 74, 435, 116);
		formToolkit.adapt(styledText);
		formToolkit.paintBordersFor(styledText);
		
		StyledText styledText_1 = new StyledText(composite_3, SWT.READ_ONLY | SWT.WRAP);
		styledText_1.setText("\t\tTamb\u00E9m pode acontecer quando voc\u00EA tem a mesma express\u00E3o em duas ou mais subclasses irm\u00E3s. Essa duplica\u00E7\u00E3o pode ser eliminada usando\t\t\t\t\t\t\t\tem todas as classes irm\u00E3s e depois\t\t\t\t\t\t\t. Se o c\u00F3digo \u00E9 semelhante mas n\u00E3o \u00E9 o mesmo, voc\u00EA precisa usar\t\t\t\t\t\t\t\t\tpara separar o que \u00E9 semelhante do que \u00E9 diferente. Em seguida, talvez voc\u00EA veja a necessidade de usar\t\t\t\t\t\t\t\t\t\t\t\t. Se os m\u00E9todos fazem a mesma coisa com um algoritmo diferente, voc\u00EA pode escolher o algoritmo mais claro (ou mais eficiente) e usar\t\t\t\t\t\t\t\t\t\t   \t\t\t\t\t\t\t\t\t.");
		styledText_1.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		styledText_1.setEnabled(false);
		styledText_1.setJustify(true);
		styledText_1.setDoubleClickEnabled(false);
		styledText_1.setBounds(463, 185, 435, 239);
		formToolkit.adapt(styledText_1);
		formToolkit.paintBordersFor(styledText_1);
		
		StyledText styledText_2 = new StyledText(composite_3, SWT.READ_ONLY | SWT.WRAP);
		styledText_2.setText("\t\tSe o c\u00F3digo duplicado est\u00E1 presente em duas classes n\u00E3o relacionadas, talvez seja o caso de usar\t\t\t\t\t\t\tem uma classe e ent\u00E3o usar o novo componente no outro. Outra possibilidade \u00E9 que o m\u00E9todo pertence em uma terceira classe que deve ser referenciada por ambas as classes originais. Voc\u00EA deve decidir onde o m\u00E9todo faz sentido e garantir que ele est\u00E1 l\u00E1 e em nenhum outro lugar.");
		styledText_2.setFont(SWTResourceManager.getFont("Segoe UI", 12, SWT.NORMAL));
		styledText_2.setEnabled(false);
		styledText_2.setJustify(true);
		styledText_2.setDoubleClickEnabled(false);
		styledText_2.setBounds(81, 441, 817, 103);
		formToolkit.adapt(styledText_2);
		formToolkit.paintBordersFor(styledText_2);
		scrolledComposite.setContent(composite_3);
		scrolledComposite.setMinSize(composite_3.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		
		TabItem tbtmUsage = new TabItem(tabFolder, SWT.NONE);
		tbtmUsage.setText("Exemplo");
		
		ScrolledComposite scrolledComposite_1 = new ScrolledComposite(tabFolder, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
		tbtmUsage.setControl(scrolledComposite_1);
		formToolkit.paintBordersFor(scrolledComposite_1);
		scrolledComposite_1.setExpandHorizontal(true);
		scrolledComposite_1.setExpandVertical(true);
		
		Composite composite = new Composite(scrolledComposite_1, SWT.NONE);
		formToolkit.adapt(composite);
		formToolkit.paintBordersFor(composite);
		
		Label label = new Label(composite, SWT.NONE);
		label.setImage(ResourceManager.getPluginImage("RefactorTips", "images/codeSmells/duplicateCode/sample1.1.png"));
		label.setBounds(10, 120, 511, 392);
		formToolkit.adapt(label, true, true);
		
		Label label_1 = new Label(composite, SWT.NONE);
		label_1.setImage(ResourceManager.getPluginImage("RefactorTips", "images/codeSmells/duplicateCode/sample1.2.png"));
		label_1.setBounds(598, 120, 509, 450);
		formToolkit.adapt(label_1, true, true);
		
		Label label_2 = new Label(composite, SWT.NONE);
		label_2.setImage(ResourceManager.getPluginImage("RefactorTips", "images/rightPointer.png"));
		label_2.setBounds(527, 307, 66, 36);
		formToolkit.adapt(label_2, true, true);
		scrolledComposite_1.setContent(composite);
		scrolledComposite_1.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		
		TabItem tbtmVideo = new TabItem(tabFolder, SWT.NONE);
		tbtmVideo.setText("Video");
		
		Browser browser = new Browser(tabFolder, SWT.NONE);
		browser.setUrl("www.youtube.com/embed/VEyvBaJMZqo");
		tbtmVideo.setControl(browser);
		formToolkit.paintBordersFor(browser);
	}
}
